<?php

/*

    ThunderZ - Web Application

    Copyright (c) 2009 Mary Jane Soft - Marlon J. Manrique

    http://www.maryjanesoft.com
    http://www.marlonj.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General
    Public License along with this library; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    Boston, MA  02111-1307  USA

    $Id$

*/

/**
 * URL for test the web application 
 */
define('TEST_BASE_URL','http://localhost/~marlonj/thunderfire/trunk/php/webapp/tf/index.php');

/**
 * The base class for functional test cases.
 * In this class, we set the base URL for the test application.
 * We also provide some common methods to be used by concrete test classes.
 */
class WebTestCase extends CWebTestCase
{
	/**
	 * Sets up before each test method runs.
	 * This mainly sets the base URL for the test application.
	 */
	protected function setUp()
	{
		parent::setUp();
		$this->setBrowserUrl(TEST_BASE_URL);

		// Set the browers cause the phpunit.xml is not read 
		$this->setBrowser("*firefox3");
	}

	/**
	 * Login like user 
	 */
	protected function login()
	{
		if($this->isElementPresent('name=TLoginFormModel[username]'))
		{
			$this->type('name=TLoginFormModel[username]','user');
			$this->type('name=TLoginFormModel[password]','user');
			$this->clickAndWait("//input[@value='Login']");
		}
	}

	/**
	 * Logs out the user
	 */
	protected function logout()
	{
		if($this->isElementPresent("link=Logout"))
			$this->clickAndWait("link=Logout");
	}

	/**
	 * Ensures the user is logged out
	 */
	protected function ensureLogout()
	{
		// Open the initial page and do logout 
		$this->open('');
		$this->logout();
	}
}

?>
